package 力扣.树.前序遍历;

public class 相同的树100 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == q){//直到两颗树为空
            return true;
        }
        if (p == null || q == null){//只有一个为空
            return  false;
        }
        return p.val == q.val &&
                isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }


    public boolean isSameTree2(TreeNode p, TreeNode q) {
        if (p == q){//直到都为空
            return true;
        }
          if (p != null && q != null){
              if (p.val == q.val){
                  return isSameTree2(p.left, q.left) && isSameTree2(p.right, q.right);
              }
          }
          return false;
    }
}

